<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      >
    <h:head>   
        <title>Cadastro de Item</title>
        <style type="text/css">
            *{
                font-size: 12px !important;
            }
            #btSalvar{
            }
            #btTodos{
                position: relative;
                top: -28px;
                left: 65px;
                /*top: 158px;
                left: 90px;*/
            }
        </style>    
    </h:head>  
    
    <p:ajaxStatus onstart="statusDialog.show();" onsuccess="statusDialog.hide();"/>  
    <p:dialog modal="true" widgetVar="statusDialog" header="Status"  
              draggable="false" closable="false" >Processando...</p:dialog>

    <h:body onload="#{loginBean.validaUsuarioSessaoPaginas}">
        <p:panel id="painel" header="Cadastro de Itens">
            <h:form id="formCadastroItem">

                <p:messages id="mensagens" />

                <h:panelGrid columns="2">

                    <h:outputText value="Descricao: "/>
                    <p:inputText id="itDescricao" label="Descricao" required="true" value="#{itemBean.item.descricao}" disabled="#{itemBean.camposDesativados}"/>

                    <h:outputText value="Valor: "/>
                    <p:inputText id="itRg" label="Valor" required="true" value="#{itemBean.item.valor}" disabled="#{itemBean.camposDesativados}"/>

                </h:panelGrid>

                <div id="btSalvar">
                    <p:commandButton id="btSalvar" value="Salvar" update=":formCadastroItem, :formTodos" actionListener="#{itemBean.salvar}" disabled="#{itemBean.salvarDesativado}"/>
                </div> 
            </h:form>

            <div id="btTodos">
                <h:form id="formTodos">
                    <p:commandButton id="btNovo" value="Novo" update=":formCadastroItem, :formTodos" actionListener="#{itemBean.novo}" disabled="#{itemBean.novoDesativado}"/>  
                    <p:commandButton id="btEditar" value="Editar" update=":formCadastroItem, :formTodos" actionListener="#{itemBean.editar}" disabled="#{itemBean.editarDesativado}"/> 
                    <p:commandButton id="btExcluir" value="Excluir" update=":formCadastroItem, :formTodos, :formPesquisaI"  actionListener="#{itemBean.excluir}" disabled="#{itemBean.excluirDesativado}"/> 
                    <p:commandButton id="btCancelar" value="Cancelar" update=":formCadastroItem, :formTodos"  actionListener="#{itemBean.cancelar}" disabled="#{itemBean.cancelarDesativado}"/>
                    <p:commandButton id="btPesquisar" value="Pesquisar" update=":formCadastroItem, :formTodos, :formPesquisaI" disabled="#{itemBean.pesquisarDesativado}" onclick="itemDialog.show()" type="button" />
                </h:form>
            </div> 
            
            <p:dialog id="dialog" header="Itens" widgetVar="itemDialog" resizable="false"  
                  width="900" height="500" showEffect="clip" hideEffect="fold">
            <h:form id="formPesquisaI">

                <h:outputLabel for="nomePessoaPesquisa" value="Nome: *" /> 
                <p:inputText id="nomePessoaPesquisa" value="#{itemBean.itemPesquisa}" />
                <p:commandButton id="btPesquisarItem" value="Pesquisar" update="formPesquisaI"  />

                <p:dataTable id="dataTableItens" var="itemVar" value="#{itemBean.filtraItemDescricao}" rowKey="#{itemVar.idItem}"  
                             widgetVar="dataTableVar" selection="#{itemBean.itemSelecionado}" selectionMode="single" emptyMessage="Item não encontrado.">

                    <f:facet name="header">  
                        Selecione um item para exclusão ou alteração.  
                    </f:facet> 

                    <p:column headerText="Nome" width="200">  
                        #{itemVar.descricao}  
                    </p:column> 
                    <p:column headerText="CPF" width="100">  
                        #{itemVar.valor}  
                    </p:column> 
                    
                    <f:facet name="footer">  
                        <p:commandButton id="btOK" value="OK" icon="ui-icon-search"  update=":formCadastroItem, :formPesquisaI" onclick="itemDialog.hide()" />  
                    </f:facet>
                </p:dataTable>

            </h:form>            
        </p:dialog>

        </p:panel>
    </h:body>
</html>
